function AllAssociationCtrl($rootScope, $scope, $state, $http) {
    $scope.onPageChange = function () {
        console.log($scope.currentPage);
        $http({
            url: 'association/all',
            method: 'get',
            params: {
                pageSize: 5,
                page: $scope.currentPage - 1
            },
        }).success(function (response) {
            $scope.list = response.content;
            $scope.pageCount = response.totalPages;
            // $scope.currentPage = response.page + 1;
        })
    };

    $scope.initPage = function () {
        console.log($scope.currentPage);
        $http({
            url: 'association/all',
            method: 'get',
            params: {
                pageSize: 5,
                page: 0
            },
        }).success(function (response) {
            $scope.list = response.content;
            $scope.pageCount = response.totalPages;
            // $scope.currentPage = response.page + 1;
        })
    };

    $scope.initPage();
}

function AssociationInfoCtrl($rootScope, $scope, $state, $http, $stateParams) {
    $scope.uid = $stateParams.uid;
    $http({
        url: 'association/uid',
        params: {
            uid: $scope.uid
        },
        method: 'get'
    }).success(function (response) {
        $scope.association = response;
    });
}

function AssociationApplyCtrl($rootScope, $scope, $state, $http, $stateParams) {
    $scope.uid = $stateParams.uid;
    $http({
        url: 'association/uid',
        params: {
            uid: $scope.uid
        },
        method: 'get'
    }).success(function (response) {
        $scope.association = response;
        $scope.data = {};
        $scope.user = {};
        $http({
            url: 'user/getCurrentUser',
            method: 'get'
        }).success(function (response) {
            $scope.user = response;
            $http({
                url: 'association/isUserExist',
                params: {
                    name: $scope.association.name
                },
                method: 'get'
            }).success(function (response) {
                if (response == 'Y') {
                    $("#applyBtn").css("display", "none");
                }
            })
        });
    });

    $scope.save = function () {
        $('#sure').modal();
    };
    $scope.submits = function (val) {
        if (val == "save") {
            $http({
                url: 'application/join/add',
                method: 'post',
                params: {
                    name: $scope.association.name,
                    description: $scope.description
                }
            }).success(function (response) {
                $('.close').click();
                $state.go('index.associationInfo', {name: $scope.association.name});
            })
        } else {
            $('.close').click();
        }
    }
}